<%@ Application Language="C#" %>

<script runat="server">
    public static int hitCount = 0;
    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        Application["FCKeditor:UserFilesPath"] = "../../../../../img/";
        Application["OnlineCounter"] = 0;
    
        //load count
        CommonDAO cd = new CommonDAO();
        hitCount = cd.chayCauSQLScalarInt("select hitCount from HitCount");
        Application["HitCount"] = hitCount;
    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
		Application.Lock();
        // Code that runs when a new session is started
        Application["OnlineCounter"] = TTQT.TTQT_Code.TTQTCommon.ToInt32(Application["OnlineCounter"],0)+1;
        hitCount = Convert.ToInt32(Application["HitCount"]);
        Application["HitCount"] = hitCount + 1;

        CommonDAO cd = new CommonDAO();
        //if(hitCount%5==0)
        //{
            cd.chayCauUpdate("update HitCount set hitcount=" + hitCount);
        //}
        Application.UnLock();
        
    }

    void Session_End(object sender, EventArgs e)
    {
		Application.Lock();
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.
        if (TTQT.TTQT_Code.TTQTCommon.ToInt32(Application["OnlineCounter"], 0)>0)
        {
            Application["OnlineCounter"] = TTQT.TTQT_Code.TTQTCommon.ToInt32(Application["OnlineCounter"], 0) - 1;
        }
		Application.UnLock();
    }
       
</script>
